#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int dis[N];
void solve() {
  int x, y;
  cin >> x >> y;
  if (x >= y) {
    cout << x - y << endl;
    return;
  }
  int mx = y * 2 - x;
  rep(i, 0, mx) dis[i] = 1e9;
  queue<int> q;
  q.push(x);
  dis[x] = 0;
  while (q.size()) {
    int x = q.front();
    q.pop();
    int nxt[] = {x - 1, x + 1, x * 2};
    for (int z : nxt) {
      if (z < 0 || z > mx) continue;
      if (dis[z] > dis[x] + 1) {
        dis[z] = dis[x] + 1;
        q.push(z);
      }
      if (z == y) {
        cout << dis[z] << endl;
        return;
      }
    }
  }
  cout << -1 << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}